  // const API_HOST = ''
import md5 from 'js-md5'
import Public from './public'
const API_HOST = Public.api
var DATA = {
  token: 'sssdsds',
  timestamp: '',
  sign: '',
  bizId: 111,
  data: { },
  pager: {
    startNo: '',
    endNo: ''
  }
}
var tookingAryy = {
  // 录入新的运输数据
  addOderPost: ({commit, state}, parm) => {
    var url = API_HOST + '/logistics/order/insertTransportData'
    parm.locateFrequency = parseInt(parm.locateFrequency)
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      //通过 commit addMapList 方法 统一注入sate
      commit('addOder', res)
    }).catch(function (res) {
      //接口回掉失败，用于组件判断当前回掉失败
      var parm ={
        body:{status: 100}
      }
      commit('updateStatusTo',parm)
    })
  },
  // 我的运输列表(运输状态为运输中的数据)
  transportListFn: ({commit, state}, parm) => {
    var url = API_HOST + '/logistics/order/transportList'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      // code 用于判断 当前数据状态 0：正常，1：接口成功但数据集合为[ ] 空，-1：接口请求失败
      if(res.body.data.length >= 1){
        res.code = 0
        commit('transportListTo', res)
      }else {
        res.code = 1
        commit('transportListTo', res)
      }
    }).catch(function (res) {
      res.code = -1
      commit('transportListTo', res)
    })
  },
  // 登陆
  loginFn: ({commit, state}, userName) => {
    var url = API_HOST + '/user/login'
    // 收集登陆参数
    var parm = {
      userName: userName.userName,
      passwd: md5(userName.password + 'IS8b9zvn')
    }
    // 获取当前时间戳
    var date = new Date()
    var time = date.getTime()
    // 获取当前token
    DATA.token = 'eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiJsb2dpbiIsImlhdCI6MTUxMzA3NDEyMSwic3ViIjoiLTEiLCJleHAiOjE1MTQ1NDUzNTAsIm5iZiI6MTUxMzA3NDEyMX0.Zc88CxsE8n_N5BNj9zMWH9zyENksT1IfdGcaKmjGGkY'
    DATA.timestamp = time
    DATA.data = parm
    // parm = '{"userName":"ivan","passwd":"e833c14c7f490a431519cb0919407a7c"}'
    var dat = JSON.stringify(parm).split('').sort().join('').split('"').join('')
    DATA.sign = md5(DATA.token + DATA.timestamp + dat)
    //console.log(md5('{"token":"eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiJsb2dpbiIsImlhdCI6MTUxMzA3NDEyMSwic3ViIjoiLTEiLCJleHAiOjE1MTQ1NDUzNTAsIm5iZiI6MTUxMzA3NDEyMX0.Zc88CxsE8n_N5BNj9zMWH9zyENksT1IfdGcaKmjGGkY","timestamp":1514453207776,"sign":"824d925397958069ea516450eaaf4028","bizId":111,"data":{"userName":"ivan","passwd":"e833c14c7f490a431519cb0919407a7c"},"pager":{"startNo":0,"endNo":0}}'))
    state.http.post(url, JSON.stringify(DATA), { emulateJSON: true }).then(function (res) {
      commit('updateUser', res)
    })
  },
  // 退出登陆
  loginOutFn: ({commit, state}, parm) => {
    var url = API_HOST + '/user/logout'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    console.log(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      commit('updateStatusTo', {body: 'out'})
    }).catch(function (res) {
      commit('updateStatusTo', {body: 'outErorr'})
    })
  },
  // 条件搜索
  searchList: ({commit, state}, parm) => {
    var url = API_HOST + 'logistics/order/search'
    var data = Public.publicLo.parmToken(parm)
    // parm = JSON.stringify(parm)
    state.http.post(url, data).then(function (res) {
      // code 用于判断 当前数据状态 0：正常，1：接口成功但数据集合为[ ] 空，-1：接口请求失败
      if(res.body.data.length >= 1){
        res.code = 0
        commit('transportListTo', res)
      }else {
        res.code = 1
        commit('transportListTo', res)
      }
    }).catch(function (res) {
      res.code = -1
      commit('transportListTo', res)
    })
  },
  // 历史记录
  history: ({commit, state}, parm) => {
    var url = API_HOST + '/logistics/order/transportHistory'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      // code 用于判断 当前数据状态 0：正常，1：接口成功但数据集合为[ ] 空，-1：接口请求失败
      if(res.body.data.length >= 1){
        res.code = 0
        commit('transportListTo', res)
      }else {
        res.code = 1
        commit('transportListTo', res)
      }
    }).catch(function (res) {
      res.code = 0
      res.code = -1
      commit('transportListTo', res)
    })
  },
  // 运输详情
  detail: ({commit, state}, parm) => {
    var url = API_HOST + '/logistics/order/transportDetail'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      commit('updateDetail', res)
    }).catch(function (res) {
      commit('updateDetail', null)
    })
  },
  // 查询号码
  checkNumber: ({commit, state}, parm) => {
    var url = API_HOST + '/logistics/order/checkNumber'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      if(res.body.data.length >= 1){
        res.code = 0
        commit('transportListTo', res)
      }else {
        res.code = 1
        commit('transportListTo', res)
      }
    }).catch(function (res) {
      res.code = -1
      commit('transportListTo', res)
    })
  },
  // 更新运输状态 transport/order/updateTansportStatus
  updateTansportStatus: ({commit, state}, parm) => {
    var url = API_HOST + '/logistics/order/updateTransportStatus'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      res.body.code = 'up'
      commit('updateStatusTo', res)
    }).catch(function (res) {
      res.body.code = 'upCatch'
      commit('updateStatusTo', {body: null})
    })
  },
  // 删除记录
  deletefn: ({commit, state}, parm) => {
    var url = API_HOST + '/logistics/order/delete'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      res.body.code = 'del'
      commit('updateStatusTo', res)
    })
  },
  // 支持的城市
  getCityList: ({commit, state}, parm) => {
    var url = API_HOST + '/user/company/cityList'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      commit('commitCityList', res)
    }).catch(function (res) {
      commit('commitCityList', null)
    })
  },
  // 跟新提单号
  updateBillon: ({commit, state}, parm) => {
    var url = API_HOST + '/logistics/order/updateLadingId'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      res.body.code = 'updateBillon'
      commit('updateStatusTo', res)
    }).catch(function (res) {
      commit('updateStatusTo', {body: null})
    })
  },
  // 设备列表
  getDeviceList: ({commit, state}, parm) => {
    var url = API_HOST + '/company/device/deviceList'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      commit('updateDeviceList', res)
    }).catch(function (res) {
      commit('updateDeviceList', null)
    })
  },
  // 用户列表
  getUserList: ({commit, state}, parm) => {
    var url = API_HOST + '/user/manage/userList'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      commit('updateUserList', res)
    }).catch(function (res) {
      commit('updateUserList', null)
    })
  },
  // 删除用户
  delUserList: ({commit, state}, parm) => {
    var url = API_HOST + '/user/manage/deleteUser'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      commit('updateStatusTo', res)
    }).catch(function (res) {
      commit('updateUserList', null)
    })
  },
  // 标记设备使用情况
  updateDeviceUsageStatus: ({commit, state}, parm) => {
    var url = API_HOST + '/company/device/updateDeviceUsageStatus'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      commit('updateStatusTo', res)
    }).catch(function (res) {
      commit('updateStatusTo', null)
    })
  },
  // 更新提城市列表
  setCityList: ({commit, state}, parm) => {
    var url = API_HOST + '/user/company/setCityList'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      commit('updateStatusTo', res)
    }).catch(function (res) {
      commit('updateUserList', null)
    })
  },
  // 添加用户
  addUser: ({commit, state}, form) => {
    var url = API_HOST + '/user/manage/insertUser'
    var parm = form
    parm.password = md5(parm.password + 'IS8b9zvn')
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      commit('updateStatusTo', res)
    }).catch(function (res) {
      commit('updateUserList', null)
    })
  },
  // 重置密码
  resetPassword: ({commit, state}, parm) => {
    var url = API_HOST + '/user/manage/resetPassword'
    parm.password = md5(parm.password + 'IS8b9zvn')
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      res.body.code = 0
      commit('updateStatusTo', res)
    }).catch(function (res) {
      res.body.code = -1
      commit('updateUserList', null)
    })
  },
  //公司列表
  getCompanyList: ({commit, state}, parm) => {
    var url = API_HOST + '/user/company/companyList'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      commit('updateCompanyList', res)
    }).catch(function (res) {
      //commit('updateUserList', null)
    })
  },
  // 添加设备记录
  addDeviceRecord: ({commit, state}, parm) => {
    var url = API_HOST + '/company/device/addDeviceRecord'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      commit('updateStatusTo', res)
    }).catch(function (res) {
      //commit('updateUserList', null)
    })
  },
  // 查询设备数据
  showManages: ({commit, state}, parm) => {
    var url = API_HOST + '/company/device/showManages'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      commit('updateRecordList', res)
    }).catch(function (res) {
      //commit('updateUserList', null)
    })
  },
  /* 蓝湾网站*/
  // 展示业务
  showBizType: ({commit, state}, parm) => {
    var url = API_HOST + '/portal/biz/showBiz'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)

    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      commit('commitUpdateList', res)
    }).catch(function (res) {
      commit('commitUpdateList', null)
    })
  },
  // 业务详情
  showBizDetails: ({commit, state}, parm) => {
    var url = API_HOST + '/portal/biz/showBizDetails'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      commit('commitBizDetails', res)
    }).catch(function (res) {
      commit('commitBizDetails', null)
    })
  },
  // 公司 简介详情
  Intro: ({commit, state}, parm) => {
    var url = API_HOST + '/portal/company/intro'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      commit('commitBizDetails', res)
    }).catch(function (res) {
      commit('commitBizDetails', null)
    })
  },
 // 新闻列表
  showNewsList: ({commit, state}, parm) => {
    var url = API_HOST + '/portal/news/showNewsList'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      commit('commitUpdateList', res)
    }).catch(function (res) {
      commit('commitUpdateList', null)
    })
  },
  // 新闻详情
  showNewsDetails: ({commit, state}, parm) => {
    var url = API_HOST + ' /portal/news/showNewsDetails'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      commit('commitBizDetails', res)
    }).catch(function (res) {
      commit('commitBizDetails', null)
    })
  },
  //添加新闻
  addNews: ({commit, state}, parm) => {
    var url = API_HOST + '/portal/news/addNews'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    console.log(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
        res.body.code = 'addNews'
        commit('updateStatusTo', res)
      }).catch(function (res) {
        res.body.code = 'addNews'
        commit('updateStatusTo', res)
      })
  },
  // 修改新闻
  updateNewsStatus: ({commit, state}, parm) => {
    var url = API_HOST + '/portal/news/updateNews'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    console.log(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      res.body.code = 'updatNews'
      commit('updateStatusTo', res)
    }).catch(function (res) {
      res.body.code = 'updatNews'
      commit('updateStatusTo', res)
    })
  },
  //添加业务类型
  addBiz: ({commit, state}, parm) => {
    var url = API_HOST + '/portal/biz/addBiz'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    console.log(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      res.body.code = 'addBiz'
      commit('updateStatusTo', res)
    }).catch(function (res) {
      res.body.code = 'addBiz'
      commit('updateStatusTo', res)
    })
  },
  //修改公司消息
  updateIntro: ({commit, state}, parm) => {
    var url = API_HOST + '/portal/company/updateIntro'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    console.log(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      res.body.code = 'updateIntro'
      commit('updateStatusTo', res)
    }).catch(function (res) {
      res.body.code = 'updateIntro'
      commit('updateStatusTo', res)
    })
  },
 //修改业务
  updateBiz: ({commit, state}, parm) => {
    var url = API_HOST + '/portal/biz/updateBiz'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    console.log(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      res.body.code = 'updateBiz'
      commit('updateStatusTo', res)
    }).catch(function (res) {
      res.body.code = 'updateBiz'
      commit('updateStatusTo', res)
    })
  },
  //删除新闻
  deleteNews: ({commit, state}, parm) => {
    var url = API_HOST + '/portal/news/deleteNews'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    console.log(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      res.body.code = 'deleteNews'
      commit('updateStatusTo', res)
    }).catch(function (res) {
      res.body.code = 'deleteNews'
      commit('updateStatusTo', res)
    })
  },
 //询价单列表
  showQuotationList: ({commit, state}, parm) => {
    var url = API_HOST + '/portal/quotation/showQuotationList'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    console.log(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      commit('commitUpdateList', res)
    }).catch(function (res) {
      commit('commitUpdateList', null)
    })
  },
  // 询价单详情
  showQuotationDetails: ({commit, state}, parm) => {
    var url = API_HOST + '/portal/quotation/showQuotationDetails'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      commit('commitBizDetails', res)
    }).catch(function (res) {
      commit('commitBizDetails', null)
    })
  },
  //添加询价单
  addQuotation: ({commit, state}, parm) => {
    var url = API_HOST + '/portal/quotation/addQuotation'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    console.log(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      res.body.code = 'addQuotation'
      commit('updateStatusTo', res)
    }).catch(function (res) {
      res.body.code = 'addQuotation'
      commit('updateStatusTo', res)
    })
  },
  //修改询价单
  updateQuotation: ({commit, state}, parm) => {
    var url = API_HOST + '/portal/quotation/updateQuotation'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    console.log(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      res.body.code = 'updateQuotation'
      commit('updateStatusTo', res)
    }).catch(function (res) {
      res.body.code = 'updateQuotation'
      commit('updateStatusTo', res)
    })
  },
  // 查询号码
  checkId: ({commit, state}, parm) => {
    var url = API_HOST + '/portal/transport/checkId'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      // code 用于判断 当前数据状态 0：正常，1：接口成功但数据集合为[ ] 空，-1：接口请求失败
      console.log(res.body.data.length)
      if(res.body.data.length >= 1){
        res.code = 0
        commit('transportListTo', res)
      }else {
        res.code = 1
        commit('transportListTo', res)
      }
    }).catch(function (res) {
      res.code = -1
      commit('transportListTo', res)
    })
  },
  // 地图列表
  mapListFn: ({commit, state}, parm) => {
    var url = API_HOST + '/portal/transport/trackQuery'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      //通过 commit addMapList 方法 统一注入sate
      commit('addMapList', res)
    }).catch(function (res) {
      commit('addMapList', null)
    })
  },
  }
export default {tookingAryy}

